import Watcher from "../core/watcher/index.js"
import Vue from "../core/index.js"

export default function mountComponent(vm) {
    const updateComponent = function () {
        vm._update(vm._render())
    }
    new Watcher(updateComponent)
}

Vue.prototype._render = function () {
    // 内部会去通过vm实例上的_c、_v构造对应vnode
    return this.$options.render.call(this)
}

Vue.prototype._update = function (vnode) {
    const preVNode = this._vnode
    this._vnode = vnode
    if (!preVNode) {
        // 说明是首次更新 传递真实节点el和虚拟dom patch函数返回创建好的真实节点
        this.__patch__(this.$el, vnode)
    } else {
        // 后续更新
        this.__patch__(preVNode, vnode)
    }
}